{include file="public/head"/}
<link rel="stylesheet" href="__LAYDMIN__/style/dtree.css" media="all">
<link rel="stylesheet" href="__LAYDMIN__/style/font/dtreefont.css" media="all">
<style>
    #demoTree{padding-top: 5px;}
   #demoTree>li{padding-left: 0;}
</style>
<div class="layui-fluid" id="LAY-app-message">
    <div class="layui-card">
        <div class="layui-card-header">分配权限</div>
        <div class="layui-card-body">
            <div class="layui-row">
                <!-- 此扩展能递归渲染一个权限树，点击深层次节点，父级节点中没有被选中的节点会被自动选中，单独点击父节点，子节点会全部 选中/去选中 -->
                <div class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">分组名称：</label>
                        <div class="layui-form-mid">
                            {$info.title}
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">选择权限：</label>
                        <div class="layui-input-block">
                            <ul id="demoTree" class="dtree" data-id="0"></ul>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input name="id" type="hidden" value="{$info.group_id}">
                            <button class="layui-btn" lay-submit lay-filter="submit">确认保存</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/foot"/}

<script>
    layui.config({
        base: '__LAYDMIN__/',{if config('app.app_debug')}version: true{/if}
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'dtree','form'],function(){
        var $ = layui.$,admin = layui.admin,dtree = layui.dtree,form = layui.form;
        var DemoTree = dtree.render({
            elem: "#demoTree",
            url: "{:url('admin/AuthGroup/access',['id'=>input('id')])}&random="+Math.random(),
            checkbar: true,  //开启复选框
            dot: false,//去除小圆点
            initLevel: 1,//折叠
            skin: "zdy"
        });
        //提交编辑
        form.on('submit(submit)', function(data){
            var dtreevVal = dtree.getCheckbarNodesParam("demoTree");

            var ids = [];
            $.each(dtreevVal, function (i, val) {
                //console.log(val);
                ids[i] = val['nodeId'];
            });
            data['field']['rules'] = ids;
			data['field']['doAction'] = 'saveAccess';
            admin.req({
                url: '{:url(SYS_PATH."/AuthGroup/access")}'
                , type: 'post'
                , data: data.field
                , success: function (res) {
						if (res.code==0) {
							window.top.layer.msg(res.msg, {icon: 1, time: 1000,shade:[0.5,'#000']}, function () {
									layer.closeAll("iframe");
									parent.location.reload();//刷新父页面
							});
						}else{
							window.top.layer.msg(res.msg, {time: 1000, icon: 2,shade:[0.5,'#000']});
						}
                }
            });
        });
    });
</script>
</body>
</html>